package org.xue.snowmall.bargain.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xue.snowmall.bargain.entity.BargainRecordEntity;
import org.xue.snowmall.bargain.service.BargainRecordService;
import org.xue.snowmall.common.utils.PageUtils;
import org.xue.snowmall.common.utils.R;

import java.util.List;
import java.util.Map;

/**
 * @author 小刘的小张
 * @version 1.0
 * @description: TODO
 * @date 2021/9/26 14:05
 */
@Controller
public class WebBargainRecordController {

    @Autowired
    private BargainRecordService bargainRecordService;
    @RequestMapping("/saveBargainRecord")
    @ResponseBody
    public R saveBargainRecord(@RequestParam("gsmBargainId") Long gsmBargainId) {
        return bargainRecordService.saveBargainRecord(gsmBargainId);
    }

    @RequestMapping("/lockMyRecord")
    public String lockMyRecord(Model model
    ,@RequestParam Map<String, Object> params) {

        PageUtils pageUtils = bargainRecordService.queryPage(params);
        List<BargainRecordEntity> list = pageUtils.getList();
        for (BargainRecordEntity bargainRecord : list) {
            if (bargainRecord.getGsmBargainRecordStatus().equals("0")) {
                bargainRecord.setGsmBargainRecordStatus("正在砍价中");
            }
            if (bargainRecord.getGsmBargainRecordStatus().equals("1")) {
                bargainRecord.setGsmBargainRecordStatus("砍价结束");
            }
        }
        model.addAttribute("list",pageUtils);
        return "bargainRecord";
    }
}
